package com.kizuki.design.chain;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class NameVerify extends Verify{

    /**
     * 检验名字是否是中文
     * @param userAccount
     */
    @Override
    protected VerifyResult handle(UserAccount userAccount) {
        String name = userAccount.getUserName();
        boolean isChinese = isChinese(name);
        log.info("校验客户名字是否是中文, name:{}, isChinese:{}", name, isChinese);
        return VerifyResult.buildResult(isChinese, "客户名字不是中文");
    }

    /**
     * 判断该字符串是否为中文
     * @param string
     * @return
     */
    private boolean isChinese(String string){
        int n;
        for(int i = 0; i < string.length(); i++) {
            n = string.charAt(i);
            if(!(19968 <= n && n <40869)) {
                return false;
            }
        }
        return true;
    }
}
